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

📄 sewin.c

📁 功能丰富的串口通讯程序
💻 C
📖 第 1 页 / 共 2 页
字号:
voidCenterShell(widget, geomParent)     Widget          widget,                     geomParent;{  Dimension width, height, borderWidth;  Position x, y, maxPos;  XtVaGetValues(geomParent, XtNwidth, &width, XtNheight, &height, NULL);  XtTranslateCoords(geomParent, (Position)width/2, (Position)height/2, 					&x, &y);  widget = GetShell(widget);  if (!XtIsRealized(widget)) XtRealizeWidget(widget);  XtVaGetValues(widget, XtNwidth, &width, XtNheight, &height, XtNborderWidth,				&borderWidth, NULL);  width += 2 * borderWidth;  height += 2 * borderWidth;  x -= (Position)width/2;  if (x < 0) x = 0;  if (x > (maxPos = (Position)(XtScreen(widget)->width - width))) 	x = maxPos;  y -= (Position)height/2;  if (y < 0) y = 0;  if (y > (maxPos = (Position)(XtScreen(widget)->height - height))) 	y = maxPos;  XtVaSetValues(widget, XtNx, x, XtNy, y, NULL);}voidCenterShellOnRoot(widget)     Widget          widget;{  Dimension width, height, borderWidth;  Position x, y;  widget = GetShell(widget);  if (!XtIsRealized(widget)) XtRealizeWidget(widget);  XtVaGetValues(widget, XtNwidth, &width, XtNheight, &height, XtNborderWidth,				&borderWidth, NULL);  width += 2 * borderWidth;  height += 2 * borderWidth;  x = (Position)(XtScreen(widget)->width - width)/2;  y = (Position)(XtScreen(widget)->height - height)/2;  XtVaSetValues(widget, XtNx, x, XtNy, y, NULL);}voidPositionShell(widget, parent, posStyle)     Widget          widget;     Widget          parent;	 int             posStyle;{  Dimension width, height /*, borderWidth*/;  Position x, y;  widget = GetShell(widget);  if (!XtIsRealized(widget)) XtRealizeWidget(widget);  switch (posStyle) {  case  SHELLPOS_HWFH:	XtVaGetValues(parent, XtNwidth, &width, XtNheight, &height, NULL);    XtTranslateCoords(parent, (Position)width/2, (Position)height, &x, &y);    XtVaSetValues(widget, XtNx, x, XtNy, y, NULL);	break;  }}WidgetSeAddPopupWG(name, parent, x_widget, y_widget, x_offset, y_offset, topLev,	     setGeom)     String          name;     Widget          parent,                     x_widget,                     y_widget;     Position        x_offset,                     y_offset;     Boolean         topLev;     Boolean         setGeom;{  Widget          popup;  Position        x,                  y,                  dummy;  if (x_widget == NULL)    x_widget = parent;  if (y_widget == NULL)    y_widget = x_widget;  if (topLev)    popup = XtVaCreatePopupShell(name, topLevelShellWidgetClass, parent,								 XtNiconPixmap, progIcon, NULL);  else    popup = XtVaCreatePopupShell(name, transientShellWidgetClass, parent,								 XtNtransientFor, GetShell(parent),								 XtNiconPixmap, progIcon, NULL);  if (setGeom) {    XtTranslateCoords(x_widget, x_offset, (Position)0, &x, &dummy);    XtTranslateCoords(y_widget, (Position)0, y_offset, &dummy, &y);    XtVaSetValues(popup, XtNx, x, XtNy, y, NULL);  }  return popup;}WidgetAddSimplePopup(name, parent)     String          name;     Widget          parent;{  return XtVaCreatePopupShell(name, transientShellWidgetClass, parent,							  XtNtransientFor, GetShell(parent),							  XtNiconPixmap, progIcon, NULL);}WidgetSeAddPopup(name, parent)     String          name;     Widget          parent;{  return SeAddPopupWG(name, parent, NULL, NULL, SeWidgetWidth(parent) / 2,		      SeWidgetHeight(parent), False, True);}WidgetSeAddPopupOffset(name, parent, geomParent)     String          name;     Widget          parent;     Widget          geomParent;{  return SeAddPopupWG(name, parent, geomParent, geomParent, 10, 10, False,		      True);}WidgetSeAddPopupUL(name, parent)     String          name;     Widget          parent;{  return SeAddPopupOffset(name, parent, XtParent(parent));}WidgetSeAddPopupSh(name, parent)     String          name;     Widget          parent;{  return SeAddPopupOffset(name, parent, GetShell(parent));}/* * pops up a message */voidSePopupMsg(parent, msg)     Widget          parent;     String          msg;{  Widget          popup,                  dialog;  Arg             args;  popup = SeAddPopup("message", parent);  XtSetArg(args, XtNlabel, msg);  dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, popup,				 &args, 1);  XawDialogAddButton(dialog, "dismiss", DestroyShell, (XtPointer)dialog);  XtPopup(popup, XtGrabExclusive);}voidSePopupMsgf(parent, fmt, a, b, c)     Widget          parent;     String          fmt,                     a,                     b,                     c;{  char            buf[REG_BUF];  sprintf(buf, fmt, a, b, c);  SePopupMsg(parent, buf);}WidgetSePopupNotice(parent, title, call_back, msg)     Widget          parent;     String          title;     void            (*call_back) ();     String          msg;{  Widget          popup,                  dialog;  popup = SeAddPopupUL("notice", parent);  XtVaSetValues(popup, XtNtitle, title, NULL);  dialog = XtVaCreateManagedWidget("dialog", dialogWidgetClass, popup,				   XtNlabel, msg, NULL);  XawDialogAddButton(dialog, "dismiss", call_back, (XtPointer) dialog);  XtPopup(popup, XtGrabExclusive);  return popup;}voidSePopupNoticeF(parent, title, call_back, fmt, a, b, c, d)     Widget          parent;     String          title;     void            (*call_back) ();     String          fmt,                     a,                     b,                     c,                     d;{  char            buf[REG_BUF];  sprintf(buf, fmt, a, b, c);  SePopupNotice(parent, title, call_back, buf);}/* * almost similar to the above */voidSeTransMsg(name, parent)     String          name;     Widget          parent;{  Widget          popup,                  dialog;  popup = SeAddPopup(name, parent);  dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, popup,				 NULL, 0);  XawDialogAddButton(dialog, "dismiss", DestroyShell, (XtPointer)dialog);  XtPopupSpringLoaded(popup);}/* * pops up a message to the effect that a feature is not implemented */voidNotImplemented(w)     Widget          w;{  SeTransMsg("notImplemented", w);}voidSeSetValue(widget, name, value)     Widget          widget;     String          name;     XtArgVal        value;{  Arg             args;  XtSetArg(args, name, value);  XtSetValues(widget, &args, 1);}/* * returns a widget's height */DimensionSeWidgetHeight(widget)     Widget          widget;{  Dimension       height;  Arg             args;  XtSetArg(args, XtNheight, &height);  XtGetValues(widget, &args, 1);  return height;}/* * sets a widget's height */voidSeSetWidgetHeight(widget, height)     Widget          widget;     Dimension       height;{  Arg             args;  XtSetArg(args, XtNheight, height);  XtSetValues(widget, &args, 1);}/* * returns a widget's width */DimensionSeWidgetWidth(widget)     Widget          widget;{  Dimension       width;  Arg             args;  XtSetArg(args, XtNwidth, &width);  XtGetValues(widget, &args, 1);  return width;}/* * sets a widget's width */voidSeSetWidgetWidth(widget, width)     Widget          widget;     Dimension       width;{  Arg             args;  XtSetArg(args, XtNwidth, width);  XtSetValues(widget, &args, 1);}/* * sets the status message */voidSetStatusMessage(msg)     String          msg;{  SeSetLabel(statusMessage, msg);/*  XFlush(XtDisplay(statusMessage));*/}/* * similar to the above, but accepts a formmat string */voidSetStatusMessagef(fmt, a, b, c)     String          fmt,                     a,                     b,                     c;{  char            buffer[REG_BUF];  sprintf(buffer, fmt, a, b, c);  SetStatusMessage(buffer);}/*---------------------------------------------------------------------------+| Beep - rings the terminal bell.+---------------------------------------------------------------------------*/voidFancyBell(widget)	 Widget          widget;{  Display                   *display = XtDisplay(widget);  XKeyboardControl          keyboardControl;  XKeyboardState            keyboardState;  static int                pitch[3] = {200, 400, 500},                            duration[3] = {50, 100, 100};  int                       i;  XGetKeyboardControl(display, &keyboardState);  for (i = 0; i < 3; i++) {	keyboardControl.bell_pitch = pitch[i];	keyboardControl.bell_duration = duration[i];	XChangeKeyboardControl(display, KBBellPitch | KBBellDuration, 						   &keyboardControl);  	XBell(display, 100);	XFlush(display);	usleep(100000L);  }  keyboardControl.bell_pitch = keyboardState.bell_pitch;  keyboardControl.bell_duration = keyboardState.bell_duration;  XChangeKeyboardControl(display, KBBellPitch | KBBellDuration, 						 &keyboardControl);}/*---------------------------------------------------------------------------+| DoDisplayFile - prepares a pop up file view.+---------------------------------------------------------------------------*/WidgetDoDisplayFile(parent, fileName)     Widget          parent;     XtPointer       fileName;{  Widget          popup,                  form;  popup = AddSimplePopup("display", parent);  form = SeAddForm("form", popup);  XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, XtNtype,						  XawAsciiFile, XtNstring, (String)fileName,						  XtNeditType, XawtextRead, XtNdisplayCaret, False,						  NULL);  AddButton("dismiss", form, DestroyShell, NULL);  return popup;}/*---------------------------------------------------------------------------+| DisplayFile - pops up a file for viewing.+---------------------------------------------------------------------------*/voidDisplayFile(parent, fileName)     Widget          parent;     XtPointer       fileName;{  Widget          popup;  popup = DoDisplayFile(parent, fileName);  CenterShell(popup, parent);   XtPopup(popup, XtGrabNone);}/*---------------------------------------------------------------------------+| DialogDisplayFile - prompts for a file name then pops up the file for |                     viewing.+---------------------------------------------------------------------------*/voidDialogDisplayFile(widget)     Widget          widget;{  GetValueByPopup(widget, "dialogDisplayFile", DisplayFile);}/*---------------------------------------------------------------------------+| EditFile - pops up a file for editing.+---------------------------------------------------------------------------*/voidEditFile(parent, fileName)     Widget          parent;     XtPointer       fileName;{  Widget          popup,                  form,                  text;  popup = AddSimplePopup("edit", parent);  form = SeAddForm("form", popup);  text = 	XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, XtNtype,							XawAsciiFile, XtNstring, (String)fileName, 							XtNeditType, XawtextEdit, XtNdisplayCaret, True,							NULL);  AddButton("save", form, EditSaveFile, (XtPointer)text);  AddButton("dismiss", form, DestroyShell, NULL);  CenterShell(popup, parent);   XtPopup(popup, XtGrabNone);}/*---------------------------------------------------------------------------+| DialogEditFile - prompts for a file name then pops up the file for editing.+---------------------------------------------------------------------------*/voidDialogEditFile(widget)     Widget          widget;{  GetValueByPopup(widget, "dialogEditFile", EditFile);}/*---------------------------------------------------------------------------+| EditSaveFile - saves the file being edited.+---------------------------------------------------------------------------*/voidEditSaveFile(widget, text)     Widget          widget;     XtPointer       text;{  Widget          textSource;  XtVaGetValues((Widget)text, XtNtextSource, &textSource, NULL);  if (XawAsciiSave(textSource) != True)    SePopupMsg(widget, "File Save Failed");}voidSeAppMainLoop(appContext)     XtAppContext    appContext;{  DoMainLoop = True;  while (DoMainLoop) XtAppProcessEvent(appContext, XtIMAll);}voidStopMainLoop(){  DoMainLoop = False;}#ifdef notdefintSeAppMSleep(appContext, msec)     XtAppContext    appContext;     unsigned long   msec;{  Widget          widget = statusMessage;  static Boolean  inSleep = False;  if (inSleep) return -1;  XtAppAddTimeOut(appContext, msec, (XtTimerCallbackProc)StopMainLoop, NULL);/*  XtAddGrab(widget, True, False);*/   inSleep = True;  SeAppMainLoop(appContext);/*  XtRemoveGrab(widget);*/  inSleep = False;  return 0;}#endif

⌨️ 快捷键说明

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