/// @todo remove the pro->text != NULL restriction? /// @todo warn that you need to free() anything from a Property void setTextProperty(TextProperty* pro, const char* text) { if (!pro) return; else if (!text) { deleteProperty(pro->text); pro->text = createProperty(); } else { setLetters(pro->text, text); } }
void CreateSpinBoxes(Widget parent_of_spin_box) { Cardinal n; Position nextY; Arg argList[25]; Widget parent; XmString decoString; /***** Set Y position for next SpinBox *****/ nextY = 10; /***** Create BulletinBoard parent for SpinBox widgets *****/ n = 0; XtSetArg(argList[n], XmNwidth, 250); n++; XtSetArg(argList[n], XmNheight, 400); n++; parent = XmCreateBulletinBoard(parent_of_spin_box, "Parent", argList, n); XtManageChild(parent); /****************************************************************/ /***** ***** Create SpinBox spin0 ***** ***** Choices: months of the year ***** ***** Callbacks: ***** - changedSpin0 Prints string desription of callback ***** reason, and prints 'new' year when boundary ***** is crossed (January to December, decrement year; ***** December to January, increment year); *****/ /***** Create SpinBox parent *****/ n = 0; XtSetArg(argList[n], XmNy, nextY); n++; spin0 = XmCreateSpinBox(parent, "spin0", argList, n); /***** Increment Y position for next SpinBox *****/ nextY += Y_OFFSET; /***** Create XmString array of month names *****/ setMonths(); /***** Create TextField child *****/ n = 0; XtSetArg(argList[n], XmNvalues, monthValues); n++; XtSetArg(argList[n], XmNnumValues, 12); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmSTRING); n++; XtSetArg(argList[n], XmNselectionPolicy, XmSINGLE_SELECT); n++; XtSetArg(argList[n], XmNeditable, False); n++; spin0_text = XmCreateTextField(spin0, "spin0_text", argList, n); /***** Manage SpinBox *****/ XtManageChild(spin0); /***** Call changedSpin0 AFTER displayed value has changed *****/ XtAddCallback(spin0, XmNvalueChangedCallback, changedSpin0, (XtPointer) 0); /***** Manage SpinBox child *****/ XtManageChild(spin0_text); /***** End of SpinBox spin0 *****/ /***** ***** Create SpinBox spin1 ***** ***** Choices: letters of the alphabet ***** ***** Callbacks: ***** - modifySpin1 Callback prevents spinning beyond ***** positions 0 (letter a) and 6 (letter g) ***** ***** - changedSpin1 Sets arrow sensitivity to inhibit wrapping ***** *****/ /***** Create SpinBox parent *****/ n = 0; XtSetArg(argList[n], XmNy, nextY); n++; XtSetArg(argList[n], XmNdefaultArrowSensitivity, XmARROWS_DECREMENT_SENSITIVE); n++; spin1 = XmCreateSpinBox(parent, "spin1", argList, n); /***** Increment Y position for next SpinBox *****/ nextY += Y_OFFSET; /***** Create XmString array of single letters *****/ setLetters(); /***** Create SpinBox child *****/ n = 0; XtSetArg(argList[n], XmNvalues, letterValues); n++; XtSetArg(argList[n], XmNnumValues, NUM_LETTERS); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmSTRING); n++; XtSetArg(argList[n], XmNarrowSensitivity, XmARROWS_INCREMENT_SENSITIVE); n++; XtSetArg(argList[n], XmNeditable, False); n++; spin1_text = XmCreateTextField(spin1, "spin0_text", argList, n); /***** Manage SpinBox *****/ XtManageChild(spin1); /***** Call modifySpin1 BEFORE displayed value is changed *****/ XtAddCallback(spin1, XmNmodifyVerifyCallback, modifySpin1, (XtPointer) 0); /***** Call changedSpin1 AFTER displayed value has changed *****/ XtAddCallback(spin1, XmNvalueChangedCallback, changedSpin1, (XtPointer) 0); /***** Manage SpinBox child *****/ XtManageChild(spin1_text); /***** End of SpinBox spin1 *****/ /***** ***** Create SpinBox spin2 ***** ***** Choices: 0.0000 to 0.0010 by .0002 ***** ***** Initial Position: 4 (displays 0.0008) ***** ***** Callbacks: none ***** *****/ /***** Create SpinBox parent *****/ n = 0; XtSetArg(argList[n], XmNy, nextY); n++; spin2 = XmCreateSpinBox( parent, "spin2", argList, n ); /***** Increment Y position for next SpinBox *****/ nextY += Y_OFFSET; n = 0; XtSetArg(argList[n], XmNposition, 4); n++; XtSetArg(argList[n], XmNdecimalPoints, 4); n++; XtSetArg(argList[n], XmNincrementValue, 2); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmNUMERIC); n++; XtSetArg(argList[n], XmNeditable, False); n++; spin2_text = XmCreateTextField( spin2, "spin2_text", argList, n ); /***** Manage SpinBox *****/ XtManageChild(spin2); /***** Manage SpinBox child *****/ XtManageChild(spin2_text); /***** End of SpinBox spin2 *****/ /***** ***** Create SpinBox spin3 ***** ***** Choices: 0.000 to 121.500 by 0.002 ***** ***** Callbacks: none ***** *****/ /***** Create SpinBox parent *****/ n = 0; XtSetArg(argList[n], XmNy, nextY); n++; XtSetArg(argList[n], XmNrepeatDelay, 250); n++; XtSetArg(argList[n], XmNarrowLayout, XmARROWS_BEGINNING); n++; spin3 = XmCreateSpinBox( parent, "spin3", argList, n ); /***** Increment Y position for next SpinBox *****/ nextY += Y_OFFSET; n = 0; XtSetArg(argList[n], XmNminimumValue, 0); n++; XtSetArg(argList[n], XmNdecimalPoints, 3); n++; XtSetArg(argList[n], XmNincrementValue, 2); n++; XtSetArg(argList[n], XmNmaximumValue, 121500); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmNUMERIC); n++; spin3_text = XmCreateTextField( spin3, "spin3_text", argList, n ); /***** Manage SpinBox *****/ XtManageChild(spin3); /***** Manage SpinBox child *****/ XtManageChild(spin3_text); /***** End of SpinBox spin3 *****/ /***** ***** Create SpinBox spin4 ***** ***** Choices: 0 to 10 by 1 ***** ***** Callbacks: ***** - modifySpin4 Callback inhibits spinning below 0 ***** at all times. Wrapping increments the maximum value. ***** *****/ /***** Create SpinBox parent *****/ n = 0; XtSetArg(argList[n], XmNy, nextY); n++; XtSetArg(argList[n], XmNarrowSize, 35); n++; XtSetArg(argList[n], XmNrepeatDelay, 250); n++; XtSetArg(argList[n], XmNinitialDelay, 500); n++; XtSetArg(argList[n], XmNarrowLayout, XmARROWS_SPLIT); n++; spin4 = XmCreateSpinBox( parent, "spin4", argList, n ); /***** Increment Y position for next SpinBox *****/ nextY += Y_OFFSET; n = 0; XtSetArg(argList[n], XmNmaximumValue, 4); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmNUMERIC); n++; spin4_text = XmCreateTextField( spin4, "spin4_text", argList, n ); /***** Manage SpinBox *****/ XtManageChild(spin4); /***** Call modifySpin4 BEFORE displayed value is changed *****/ XtAddCallback(spin4, XmNmodifyVerifyCallback, modifySpin4, (XtPointer) 0); /***** Manage SpinBox child *****/ XtManageChild(spin4_text); /***** End of SpinBox spin4 *****/ /***** ***** Create SpinBox spin5 ***** ***** Choices: 0 to 10 by 1 ***** ***** Delay: Repeat delay is 0 - displayed value only increments ***** or decrements ONCE each time arrow is armed ***** ***** Callbacks: none ***** *****/ /***** Create SpinBox parent *****/ n = 0; XtSetArg(argList[n], XmNy, nextY); n++; XtSetArg(argList[n], XmNarrowSize, 20); n++; XtSetArg(argList[n], XmNrepeatDelay, 0); n++; XtSetArg(argList[n], XmNarrowLayout, XmARROWS_BEGINNING); n++; spin5 = XmCreateSpinBox( parent, "spin5", argList, n ); /***** Increment Y position for next SpinBox *****/ nextY += Y_OFFSET; n = 0; XtSetArg(argList[n], XmNminimumValue, 1); n++; XtSetArg(argList[n], XmNposition, 1); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmNUMERIC); n++; XtSetArg(argList[n], XmNeditable, False); n++; spin5_text = XmCreateTextField( spin5, "spin5_text", argList, n ); /***** Manage SpinBox *****/ XtManageChild(spin5); /***** Manage SpinBox child *****/ XtManageChild(spin5_text); /***** End of SpinBox spin5 *****/ /***** ***** Create SpinBox spin6 ***** ***** This example has multiple children, including two ***** decoration children. In addition, this SpinBox ***** includes 'chaining', the process where a change ***** in one child causes values to change in the child ***** and on or more other children. Chaining is performed ***** by the valueChanged callback. ***** ***** Choices: spin6_text1 1 to 12 (months) ***** spin6_deco1 '/' decoration ***** spin6_text2 1 to 28-31 (max days varies by month) ***** spin6_deco2 '/' decoration ***** spin6_text3 0 to 99 (years) ***** ***** Callbacks: ***** - changedSpin6 sets maximum days in month. The month field ***** is chained to the day field, and the year field is ***** chained to the month field. (When the day child ***** wraps, the month child is also changed. When the ***** month child wraps, the year child is also changed.) ***** *****/ /***** Create SpinBox parent *****/ n = 0; XtSetArg(argList[n], XmNy, nextY); n++; XtSetArg(argList[n], XmNinitialDelay, 0); n++; XtSetArg(argList[n], XmNrepeatDelay, 150); n++; spin6 = XmCreateSpinBox( parent, "spin6", argList, n ); /***** Increment Y position for next SpinBox *****/ nextY += Y_OFFSET; /***** Create SpinBox child *****/ n = 0; XtSetArg(argList[n], XmNwidth, 30); n++; XtSetArg(argList[n], XmNposition, thisMM - 1); n++; XtSetArg(argList[n], XmNminimumValue, 1); n++; XtSetArg(argList[n], XmNmaximumValue, 12); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmNUMERIC); n++; spin6_text1 = XmCreateTextField( spin6, "spin6_text1", argList, n ); /***** Create SpinBox decoration child *****/ n = 0; decoString = XmStringCreateLtoR("/", XmSTRING_DEFAULT_CHARSET); XtSetArg(argList[n], XmNlabelString, decoString); n++; spin6_deco1 = XmCreateLabel( spin6, "spin6_deco1", argList, n ); /***** Create SpinBox child *****/ n = 0; XtSetArg(argList[n], XmNwidth, 30); n++; XtSetArg(argList[n], XmNposition, thisDD - 1); n++; XtSetArg(argList[n], XmNminimumValue, 1); n++; XtSetArg(argList[n], XmNmaximumValue, 31); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmNUMERIC); n++; spin6_text2 = XmCreateTextField( spin6, "spin6_text2", argList, n ); /***** Create SpinBox decoration child *****/ n = 0; decoString = XmStringCreateLtoR("/", XmSTRING_DEFAULT_CHARSET); XtSetArg(argList[n], XmNlabelString, decoString); n++; spin6_deco2 = XmCreateLabel( spin6, "spin6_deco2", argList, n ); XmStringFree(decoString); /***** Create SpinBox child *****/ n = 0; XtSetArg(argList[n], XmNwidth, 30); n++; XtSetArg(argList[n], XmNposition, thisYY); n++; XtSetArg(argList[n], XmNmaximumValue, 99); n++; XtSetArg(argList[n], XmNspinBoxChildType, XmNUMERIC); n++; spin6_text3 = XmCreateTextField( spin6, "spin6_text3", argList, n ); /***** Manage SpinBox *****/ XtManageChild(spin6); /***** Call changedSpin6 AFTER displayed value has changed *****/ XtAddCallback(spin6, XmNvalueChangedCallback, changedSpin6, (XtPointer) 0); /***** Manage SpinBox children *****/ XtManageChild(spin6_text1); XtManageChild(spin6_deco1); XtManageChild(spin6_text2); XtManageChild(spin6_deco2); XtManageChild(spin6_text3); /***** End of SpinBox spin6 *****/ }