int processCustomerRequest(String* name, String* object, int quantity, int num) { String Bottles = StringCreate("Bottles"); String Diapers = StringCreate("Diapers"); String Rattles = StringCreate("Rattles"); int error = 0; if (StringIsEqualTo(object, &Bottles)) { if (quantity <= store_inv.bottles) { store_inv.bottles -= quantity; customers[num].bottles += quantity; error = 0; } else { //error message printf("Sorry "); StringPrint(name); printf(", we only have %d Bottles\n", store_inv.bottles); error = 1; } } else if (StringIsEqualTo(object, &Diapers)) { if (quantity <= store_inv.diapers) { store_inv.diapers -= quantity; customers[num].diapers += quantity; error = 0; } else { //error message printf("Sorry "); StringPrint(name); printf(", we only have %d Diapers\n", store_inv.diapers); error = 1; } } else if (StringIsEqualTo(object, &Rattles)) { if (quantity <= store_inv.rattles) { store_inv.rattles -= quantity; customers[num].rattles += quantity; error = 0; } else { //error message printf("Sorry "); StringPrint(name); printf(", we only have %d Rattles\n", store_inv.rattles); error = 1; } } StringDestroy(&Bottles); StringDestroy(&Diapers); StringDestroy(&Rattles); if (error == 0) { return 0; } else { return 1; } }
boolean ScaleObj::SetName(char *name) { XmString xm_string = StringCreate(name); XtVaSetValues(_w, XmNtitleString, xm_string, NULL); StringFree(xm_string); return true; }
void IconObj::TopString(char *topString) { delete _topString; _topString = STRDUP(topString); XmString xm_string = StringCreate(topString); XtVaSetValues(_w, GuiNtopLabelString, xm_string, NULL); StringFree(xm_string); }
void Container::DoUpdateMessage(char *message) { StringFree(_xm_update_message); _xm_update_message = StringCreate(message); if (XtIsRealized(_workArea)) XClearArea(display, XtWindow(XtParent(_workArea)), 0, 0, 0, 0, TRUE); Refresh(); }
void IconObj::BottomString(char *bottomString) { delete _bottomString; _bottomString = STRDUP(bottomString); XmString xm_string = StringCreate(bottomString); XtVaSetValues(_w, GuiNbottomLabelString, xm_string, NULL); StringFree(xm_string); }
int main(void) { String s = StringCreate("Craig"); String t = s; // YOU STILL ONLY HAVE ONE STRING. Remember that t is a shallow reference, only a pointer to the same string. // printf() won't work since our string doesn't have a null terminator printf("Hello "); StringPrint(s); printf(" I see you're %d characters long\n", s.length); // using s.ptr and s.length is BAD, don't do this for the project! StringDestroy(s); }
void MotifUI::StringWidthHeight(const char *string, int *width, int *height) { Dimension w, h; XmString xm_string = StringCreate((char *)string); XmStringExtent(userFont, xm_string, &w, &h); *width = w; *height = h; StringFree(xm_string); }
boolean MotifUI::SetName(char *name) { if (!InnerWidget()) return false; XmString xm_string = StringCreate(name); XtVaSetValues(InnerWidget(), XmNlabelString, xm_string, NULL); StringFree(xm_string); return true; }
void IconObj::SetDetail() { if (!_details) return; char *name = new char [strlen(_name) + strlen(_details) + 3]; sprintf(name, "%s %s", _name, _details); XmString xm_string = StringCreate(name); XtVaSetValues(_w, XmNlabelString, xm_string, NULL); StringFree(xm_string); delete [] name; }
boolean Group::SetName(char *name) { if (name) { XmString xm_string = StringCreate(name); XtVaSetValues(_label, XmNlabelString, xm_string, NULL); StringFree(xm_string); XtManageChild(_label); } else XtUnmanageChild(_label); return true; }
int main(void) { String s = StringCreate("Craig"); String t = StringDup(s); t = s; printf("Hello "); StringPrint(s); printf(" I see you're %d characters long\n", StringSize(s)); StringDestroy(s); StringDestroy(t); }
void processInventory() { String object; int quantity; String Bottles = StringCreate("Bottles"); String Diapers = StringCreate("Diapers"); String Rattles = StringCreate("Rattles"); readString(&object); readNum(&quantity); if (StringIsEqualTo(&object, &Bottles)) { store_inv.bottles += quantity; } else if (StringIsEqualTo(&object, &Diapers)) { store_inv.diapers += quantity; } else if (StringIsEqualTo(&object, &Rattles)) { store_inv.rattles += quantity; } StringDestroy(&object); StringDestroy(&Bottles); StringDestroy(&Diapers); StringDestroy(&Rattles); }
void Menu::CreateTitle(Widget /*parent*/, char *title, char * /*category*/) { XmString xm_string = StringCreate(title); if (_title) XtVaSetValues(_title, XmNlabelString, xm_string, NULL); else { _title = XtVaCreateManagedWidget("title", xmLabelWidgetClass, _w, XmNlabelString, xm_string, NULL); _sep = XtVaCreateManagedWidget("separator", xmSeparatorWidgetClass, _w, XmNseparatorType, XmDOUBLE_LINE, NULL); } StringFree(xm_string); }
void ScaleObj::CreateScale(MotifUI *parent, char *title, int value, int numDecimalPoints, int max, int min, int scaleMultiple, ScaleType style, boolean showValue) { _style = style; _value = value; _numDecimalPoints = numDecimalPoints; _max = max; _min = min; _scaleMultiple = scaleMultiple; _style = style; _showValue = showValue; CheckValues(false); int orientation; short points = _numDecimalPoints; if (_style == VERTICAL_SCALE) orientation = XmVERTICAL; else orientation = XmHORIZONTAL; XmString xm_string = StringCreate(title); _w = XtVaCreateManagedWidget(title, xmFormWidgetClass, parent->InnerWidget(), NULL); _minLabel = XtVaCreateWidget(title, xmLabelWidgetClass, _w, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, NULL); _maxLabel = XtVaCreateWidget(title, xmLabelWidgetClass, _w, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); _scale = XtVaCreateManagedWidget(title, xmScaleWidgetClass, _w, XmNmaximum, _max, XmNminimum, _min, XmNvalue, _value, XmNscaleMultiple, _scaleMultiple, XmNdecimalPoints, points, XmNtitleString, xm_string, XmNshowValue, _showValue, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNorientation, orientation, NULL); StringFree(xm_string); SetString(_minLabel, _min); SetString(_maxLabel, _max); ShowValue(_showValue); }
void Menu::CreateMenu(Widget parent, char *name, char * /*category*/, char *mnemonic, MenuType menu_type) { XmString xm_string = StringCreate(name); _title = NULL; _sep = NULL; switch (_menu_type = menu_type) { case PULLDOWN_MENU: _w = XmCreatePulldownMenu(parent, "pulldown_menu", NULL, 0); break; case OPTION_MENU: _w = XmCreateOptionMenu(parent, "option_menu", NULL, 0); break; case POPUP_MENU: _w = XmCreatePopupMenu(parent, "popup_menu", NULL, 0); XtVaSetValues(_w, XmNwhichButton, MotifUI::bMenuButton, NULL); break; } if (_menu_type != POPUP_MENU) { _cascadeButton = XtVaCreateManagedWidget("cascadeButton", xmCascadeButtonWidgetClass, parent, XmNlabelString, xm_string, XmNsubMenuId, _w, NULL); if (depth == 1) { Pixel bg; XtVaGetValues(_cascadeButton, XmNbackground, &bg, NULL); if (bg == white) { XtVaSetValues(_w, XmNuserData, (XtPointer)this, NULL); XtAddCallback(_w, XmNmapCallback, &(Menu::MapCB), NULL); XtAddCallback(_w, XmNunmapCallback, &(Menu::MapCB), NULL); } } } StringFree(xm_string); if (mnemonic) XtVaSetValues(_cascadeButton, XmNmnemonic, XStringToKeysym(mnemonic), NULL); InstallHelpCB(); }
void IconObj::Field(int index, char *string, int width, boolean visible, boolean active) { XmString s; Dimension wid; unsigned char alignment; Boolean draw_field; Boolean selected; Boolean _active; GuiIconGetField(_w, index, &s, &wid, &alignment, &draw_field, &selected, &_active); draw_field = visible; _active = active; wid = (Dimension) width; s = StringCreate(string); GuiIconSetField(_w, index, s, wid, alignment, draw_field, selected, _active); }
void ScaleObj::SetString(Widget w, int value) { char number[20]; if (_numDecimalPoints == 0) sprintf(number, "%d", value); else { char fmt[10]; sprintf(fmt, "%%.%df", _numDecimalPoints); int n = 1, i; for (i = 0; i < _numDecimalPoints; i++) n *= 10; sprintf(number, fmt, (float) value / n); } XmString xm_string = StringCreate(number); XtVaSetValues(w, XmNlabelString, xm_string, NULL); StringFree(xm_string); }
Group::Group(MotifUI *parent, char *name, GroupType group_type) : MotifUI(parent, name, NULL) { Widget parentW; _group_type = group_type; parentW = parent->InnerWidget(); XmString xm_string = StringCreate(name); _w = XtVaCreateManagedWidget(name, xmFrameWidgetClass, parentW, NULL); if (name) _label = XtVaCreateManagedWidget(name, xmLabelWidgetClass, _w, XmNchildType, XmFRAME_TITLE_CHILD, XmNlabelString, xm_string, NULL); else _label = XtVaCreateWidget(name, xmLabelWidgetClass, _w, XmNchildType, XmFRAME_TITLE_CHILD, XmNlabelString, xm_string, NULL); if (group_type == FORM_BOX) _rc = XtVaCreateManagedWidget(name, xmFormWidgetClass, _w, NULL); else { boolean flag; int orientaion; if (group_type == RADIO_GROUP || group_type == HORIZONTAL_RADIO_GROUP) flag = true; else flag = false; if (group_type == HORIZONTAL_CHECK_BOX || group_type == HORIZONTAL_RADIO_GROUP) orientaion = XmHORIZONTAL; else orientaion = XmVERTICAL; _rc = XtVaCreateManagedWidget(name, xmRowColumnWidgetClass, _w, XmNradioBehavior, flag, XmNorientation, orientaion, NULL); } StringFree(xm_string); }
boolean IconObj::SetIcon(IconStyle style) { Pixmap pixmap, mask; int shrinkOutline = false; int pixmapPlacement; int alignment; int isOpened; BaseUI *parent = Parent(); if (ContainerView() == TREE) isOpened = true; else if (parent && parent->UISubClass() == ICON_LIST || parent->UISubClass() == SCROLLED_ICON_LIST) isOpened = true; else isOpened = Open(); switch (style) { case NAME_ONLY: pixmapPlacement = GuiPIXMAP_LEFT; alignment = XmALIGNMENT_BEGINNING; if (_name) { pixmap = XmUNSPECIFIED_PIXMAP; mask = XmUNSPECIFIED_PIXMAP; } else { pixmap = _smallPixmap; mask = _smallMask; } break; case VERY_LARGE_ICON: case LARGE_ICON: case MEDIUM_ICON: if (ContainerView() == TREE || (parent->UIClass() == CONTAINER && parent->UISubClass() == SCROLLED_VERTICAL_ROW_COLUMN)) { isOpened = true; pixmapPlacement = GuiPIXMAP_LEFT; } else pixmapPlacement = GuiPIXMAP_TOP; if (isOpened) alignment = XmALIGNMENT_BEGINNING; else alignment = LargeIconJustification; shrinkOutline = true; if (style == VERY_LARGE_ICON) { if (depth == 1) strcat(_iconFile, ".l.bm"); else strcat(_iconFile, ".l.pm"); GetPixmaps(_w, _iconFile, &pixmap, &mask); _iconFile[strlen(_iconFile) - 5] = '\0'; } else { pixmap = _largePixmap; mask = _largeMask; } break; case DETAILS: SetDetail(); // no break case SMALL_ICON: case TINY_ICON: alignment = XmALIGNMENT_BEGINNING; pixmapPlacement = GuiPIXMAP_LEFT; pixmap = _smallPixmap; mask = _smallMask; break; } if (_previous_style == DETAILS) { XmString xm_string = StringCreate(_name); XtVaSetValues(_w, XmNlabelPixmap, pixmap, GuiNiconMask, mask, XmNlabelString, xm_string, XmNalignment, alignment, GuiNpixmapPlacement, pixmapPlacement, GuiNisOpened, isOpened, GuiNshrinkOutline, shrinkOutline, NULL); StringFree(xm_string); } else XtVaSetValues(_w, XmNlabelPixmap, pixmap, GuiNiconMask, mask, GuiNpixmapPlacement, pixmapPlacement, XmNalignment, alignment, GuiNisOpened, isOpened, GuiNshrinkOutline, shrinkOutline, NULL); _previous_style = style; if (_stateIconName) SetStateIconFile(style); return true; }
void Button::CreateButton(MotifUI *parent, char *name, char * /*category*/, ButtonType button_type, ButtonCallback callback, void * callback_data, char *mnemonic, char *acceleratorText, char *accelerator, char *iconFile) { int IsArrow = false; XmString xm_string = StringCreate(name); Widget parentW; Widget super_node = NULL; _iconFile = NULL; _button_type = button_type; if (parent->UIClass() == DIALOG) parentW = parent->BaseWidget(); else if (parent->UIClass() == ICON) { parentW = XtParent(parent->InnerWidget()); super_node = parent->InnerWidget(); } else parentW = parent->InnerWidget(); if (button_type == PUSH_BUTTON) _w = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, parentW, XmNlabelString, xm_string, XmNaccelerator, accelerator, XmNmultiClick, XmMULTICLICK_DISCARD, GuiNsuperNode, super_node, NULL); else if (button_type == TOGGLE_BUTTON) _w = XtVaCreateManagedWidget("toggle", xmToggleButtonWidgetClass, parentW, XmNlabelString, xm_string, XmNaccelerator, accelerator, XmNmultiClick, XmMULTICLICK_DISCARD, GuiNsuperNode, super_node, NULL); else { int dir; switch (button_type) { case UP_ARROW_BUTTON: dir = XmARROW_UP; case DOWN_ARROW_BUTTON: dir = XmARROW_DOWN; case LEFT_ARROW_BUTTON: dir = XmARROW_LEFT; case RIGHT_ARROW_BUTTON: dir = XmARROW_RIGHT; } _w = XtVaCreateManagedWidget("arrow", xmArrowButtonWidgetClass, parentW, XmNmultiClick, XmMULTICLICK_DISCARD, XmNarrowDirection, dir, NULL); IsArrow = true; } StringFree(xm_string); if (!IsArrow) { if (mnemonic) XtVaSetValues(_w, XmNmnemonic, XStringToKeysym(mnemonic), NULL); if (acceleratorText) { xm_string = StringCreate(acceleratorText); XtVaSetValues(_w, XmNacceleratorText, xm_string, NULL); StringFree(xm_string); } } _callback = callback; _callback_data = callback_data; if (button_type == TOGGLE_BUTTON) XtAddCallback(_w, XmNvalueChangedCallback, &Button::ActivateCB, (XtPointer) this); else XtAddCallback(_w, XmNactivateCallback, &Button::ActivateCB, (XtPointer) this); InstallHelpCB(); IconFile(iconFile); }
void IconObj::CreateIconObj(MotifUI *parent, char *name, char * /*category*/, char *iconFile, char *details, char *topString, char *bottomString, IconFields _fields) { Pixmap pixmap; Pixmap mask; Pixel bg; Widget p, super_node; XmString xm_string, xm_topString, xm_bottomString; char *s; int shrinkOutline = false; int pixmapPlacement; int alignment; int isOpened; GuiIconFields gui_fields; if (fields = _fields) { int i; gui_fields = new GuiIconFieldsStruct; gui_fields->free_data = True; gui_fields->name_width = fields->name_width; gui_fields->field_spacing = fields->field_spacing; gui_fields->n_fields = fields->n_fields; gui_fields->selected = new Boolean[fields->n_fields]; gui_fields->draw_fields = new Boolean[fields->n_fields]; gui_fields->active = new Boolean[fields->n_fields]; gui_fields->widths = new Dimension[fields->n_fields]; gui_fields->alignments = new unsigned char[fields->n_fields]; gui_fields->fields = new XmString[fields->n_fields]; unsigned char alignment; for (i = 0; i < fields->n_fields; i++) { gui_fields->widths[i] = fields->fields_widths[i]; switch (fields->alignments[i]) { case LEFT_JUSTIFIED: alignment = XmALIGNMENT_BEGINNING; break; case CENTERED: alignment = XmALIGNMENT_CENTER; break; case RIGHT_JUSTIFIED: alignment = XmALIGNMENT_END; break; } gui_fields->alignments[i] = alignment; if (fields->active) gui_fields->active[i] = (Boolean)fields->active[i]; else gui_fields->active[i] = True; if (fields->draw_fields) gui_fields->draw_fields[i] = (Boolean)fields->draw_fields[i]; else gui_fields->draw_fields[i] = True; gui_fields->selected[i] = False; gui_fields->fields[i] = StringCreate(fields->fields[i]); } } else gui_fields = NULL; // Get small and large pixmaps and masks char icon_type = 'p'; if (depth == 1) icon_type = 'b'; _iconFile = new char [strlen(iconFile) + 6]; _topString = STRDUP(topString); _bottomString = STRDUP(bottomString); _details = STRDUP(details); if (display == NULL) { strcpy(_iconFile, iconFile); _stateIconName = NULL; return; } sprintf(_iconFile, "%s.t.%cm", iconFile, icon_type); GetPixmaps(parent->BaseWidget(), _iconFile, &_smallPixmap, &_smallMask); sprintf(_iconFile, "%s.m.%cm", iconFile, icon_type); GetPixmaps(parent->BaseWidget(), _iconFile, &_largePixmap, &_largeMask); strcpy(_iconFile, iconFile); s = name; BaseUI *par = Parent(); if (par && par->UISubClass() == ICON_LIST || par->UISubClass() == SCROLLED_ICON_LIST) isOpened = true; else isOpened = false; switch (IconView()) { case NAME_ONLY: pixmapPlacement = GuiPIXMAP_LEFT; alignment = XmALIGNMENT_BEGINNING; pixmap = mask = XmUNSPECIFIED_PIXMAP; break; case LARGE_ICON: if (ContainerView() == TREE || (Parent()->UIClass() == CONTAINER && Parent()->UISubClass() == SCROLLED_VERTICAL_ROW_COLUMN)) { isOpened = true; pixmapPlacement = GuiPIXMAP_LEFT; } else pixmapPlacement = GuiPIXMAP_TOP; if (isOpened) alignment = XmALIGNMENT_BEGINNING; else alignment = LargeIconJustification; shrinkOutline = true; pixmap = _largePixmap; mask = _largeMask; break; case DETAILS: s = new char [STRLEN(name) + STRLEN(details) + 2]; if (details) sprintf(s, "%s %s", name, details); else strcpy(s, name); // no break case SMALL_ICON: alignment = XmALIGNMENT_BEGINNING; pixmapPlacement = GuiPIXMAP_LEFT; pixmap = _smallPixmap; mask = _smallMask; break; } // Get Parent and colors p = parent->InnerWidget(); if (!XtIsComposite(p)) p = XtParent(p); XtVaGetValues(p, XmNbackground, &bg, NULL); // If p is a icon then set superNode to it, otherwise set superNode to NULL super_node = GuiIsIcon(parent->BaseWidget()) ? parent->BaseWidget() : NULL; xm_string = StringCreate(s); xm_topString = StringCreate(topString); xm_bottomString = StringCreate(bottomString); Pixel text_select_color = black; Pixel select_color = white; if (select_color == bg) { text_select_color = white; select_color = black; } _w = XtVaCreateManagedWidget(name, iconWidgetClass, p, GuiNiconMask, mask, XmNlabelPixmap, pixmap, GuiNisOpened, isOpened, XmNalignment, alignment, GuiNsuperNode, super_node, GuiNpixmapPlacement, pixmapPlacement, GuiNshrinkOutline, shrinkOutline, GuiNselectColorPersistent, true, GuiNselectColor, select_color, GuiNtextSelectColor, text_select_color, XmNlabelString, xm_string, GuiNfields, gui_fields, XmNbackground, bg, GuiNtopLabelString, xm_topString, GuiNbottomLabelString, xm_bottomString, XmNuserData, this, NULL); StringFree(xm_string); StringFree(xm_topString); StringFree(xm_bottomString); // Delete s if style = details if (IconView() == DETAILS) delete s; _previous_style = IconView(); XtAddCallback(_w, GuiNsingleClickCallback, &IconObj::SingleClickCB, (XtPointer) this); XtAddCallback(_w, GuiNdoubleClickCallback, &IconObj::DoubleClickCB, (XtPointer) this); InstallHelpCB(); _stateIconName = NULL; }