Home |
Class PegSpinButton HMI (Human-Machine Interface) Classes |
Class PegSpinButtonPegSpinButton is a thumbwheel style control that is normally used to adjust a numeric value displayed in an adjacent object. PegSpinButton objects can be horizontal or vertical in orientation. The are two forms of PegSpinButton. The first form is created when the spin button has a 'buddy' object. A buddy object is a PegTextThing derived object that is automatically updated as the spin button is manipulated by the end user. The second form of PegSpinButton has no buddy object, and therefore reports spin button selection to the parent window for application level processing. When a spin button has a buddy object, that object should be designed to display a numeric value. When the spin button is operated by the end user, the spin button will first convert the buddy object string to an integer, then increment or decrement the integer value as required, and then convert the integer value back to a string for assignment to the buddy object. The buddy object, if any, is required to have TT_COPY style. This is required because the string value assigned to the buddy object is dynamically constructed. If the buddy object does not have TT_COPYstyle, this style is added automatically by the spin button object. class PegSpinButton : public PegThing { public: PegSpinButton(int iLeft, int iTop, PEGUINT wId = 0, PEGUINT wStyle = AF_ENABLED | SB_VERTICAL); PegSpinButton(int iLeft, int iTop, PegTextThing * buddy, LONG lMin, LONG lMax, int iStep, PEGUINT wId = 0, PEGUINT wStyle = AF_ENABLED | SB_VERTICAL); PegSpinButton(const PegRect &Rect, PEGUINT wId = 0, PEGUINT wStyle = AF_ENABLED | SB_VERTICAL); PegSpinButton(const PegRect &Rect, PegTextThing * buddy, LONG lMin, LONG lMax, int iStep, PEGUINT wId =0, PEGUINT wStyle = AF_ENABLED | SB_VERTICAL); virtual PEGINT Message(const PegMessage &Mesg); void SetLimits(LONG lMin, LONG lMax, int iStep = -1); void SetBuddy(PegTextThing * Buddy); void SetOutputWidth(int iWidth); }; Demo program PegDemo uses this class. Style FlagsSignalsPSF_SPIN_MORE and PSF_SPIN_LESS are sent to the parent window as the spin button is selected by the end user. ConstructorsThe first two constructors are used to create a PegSpinButton that has no buddy object. These spin buttons will send notification signals to the parent object as the spin button is operated. The first version create a PegSpinButton with default width and height, which is PEG_SCROLL_WIDTH. The third and fourth constructors are used to create a PegSpinButton has a buddy object. These spin buttons directly update the buddy object, in addition to sending PSF_SPIN_MORE and PSF_SPIN_LESS signals to the button parent. The third version create a PegSpinButton with default width and height, which is PEG_SCROLL_WIDTH. The fourth version creates a PegSpinButton with a fully defined size. Method MessagePegSpinButton catches messages from the spin button directional selection arrows to update the buddy object or send signals to the spin button parent. Method SetBuddyResets the buddy object pointer of the spin button. Method SetLimitsResets the spin button limits and step value. A positive step value causes the spin button to increase the value of a buddy object when the "Up" or "Right" spin buttons are pressed. A negative step value reverses the direction of increment/decrement. Method SetOutputWidthSpecifies a fixed-width output format for spin buttons with a buddy object. The iWidth parameter indicates how many digits the output value should contain. The output string is left-padded with zeros if required to fill the indicated width. ExamplesThe following illustrates a vertical PegSpinButton with a PegPrompt buddy object: The following function creates a PegPrompt for displaying a numeric value. The prompt will be updated by a vertical PegSpinButton object. The range of values will be 20 through 80, and the value will increment/decrement by 5 each time the spin button is operated. void MyWindow::AddSpinPrompt(void) { PegRect ChildRect; ChildRect.Set(20, 20, 100, 40); PegPrompt * pPrompt = new PegPrompt(PromptRect, "20", 0, FF_RECESSED | TJ_RIGHT | TT_COPY); Add(pPrompt); // set the spin button position to the right of the prompt: ChildRect.wLeft = pPrompt->mReal.wRight + 1; ChildRect.wRight = ChildRect.wLeft + PEG_SCROLL_WIDTH; PegSpinButton * pSpin = new PegSpinButton(ChildRect, pPrompt, 20, 80, 5, SB_VERTICAL); Add(pSpin); }
|