Home |
Class PegComboBox HMI (Human-Machine Interface) Classes |
Class PegComboBoxPegComboBox is similar to PegVertList. PegComboBox is a container that can have any type of other objects added to it. PegComboBox adds the concept of Opening and Closing, which can conserve space when a large number of items are added to the combo box. An drop-down arrow is provided to open the combo box, and the box closes when an item it selected or the combo box loses focus. PegComboBox will send signal notifications to the parent window if the ComboBox has a non-zero ID value and the selected child also has a non-zero ID value. The last child added to the combo box will be displayed at the top of the combo box if the Add() function is used to add children. The order of display can be reversed by using the function AddToEnd() to add children to the combo box. If PegPrompt objects are added to a PegComboBox, the style flags for the PegPrompt objects should include FF_NONE | AF_ENABLED | TJ_LEFT for correct display. Normally PegPrompt objects are not selectable (i.e. the AF_ENABLED style is not used). However, when PegPrompt objects are added to a PegComboBox, you should set the style as shown above so that the prompt objects can be selected. class ComboList : public PegVertList { public: ComboList(PegComboBox * pBox, PegRect &Size, PEGUINT wId, PEGUINT wStyle); virtual PEGINT Message(const PegMessage &Mesg); virtual void PositionChildren(void) { PegVertList::PositionChildren(); } }; class PegComboBox : public PegThing { public: PegComboBox(const PegRect &Rect, PEGUINT wId = 0, PEGUINT wStyle = FF_THIN); virtual ~PegComboBox(); virtual PEGINT Message(const PegMessage &Mesg); virtual void Draw(void); virtual void Add(PegThing * pChild, BOOL bDraw = TRUE); virtual void AddToEnd(PegThing * pChild, BOOL bDraw = TRUE); virtual PegThing * Remove(PegThing * pChild, BOOL bDraw = TRUE); virtual void Resize(PegRect NewSize); void SetScrollMode(UCHAR uMode); PEGINT GetOpenHeight(void); BOOL IsOpen(void); void CloseList(void); virtual void Insert(PegThing * What, PEGINT Where, BOOL bSelect=TRUE, BOOL bDraw = TRUE) { mpList->Insert(What, Where, bSelect, bDraw); } virtual PegThing * GetSelected(void) { return mpList->GetSelected(); } virtual void SetSelected(PegThing *Who) { mpList->SetSelected(Who); } virtual PEGINT GetIndex(PegThing *Who) { return mpList->GetIndex(Who); } virtual PEGINT GetSelectedIndex(void) { return mpList->GetSelectedIndex(); } virtual PegThing * SetSelected(PEGINT iIndex) { return mpList->SetSelected(iIndex); } virtual PEGINT Clear() { return mpList->Clear(); } PegThing * SelectNext(void) { return mpList->SelectNext(); } PegThing * SelectPrevious(void) { return mpList->SelectPrevious(); } PegThing * PageDown(void) { return mpList->PageDown(); } PegThing * PageUp(void) { return mpList->PageUp(); } void SetSeparation(PEGINT iSep) { mpList->SetSeparation(iSep); } PEGINT GetNumItems(void) { return mpList->GetNumItems(); } enum ButtonIds { IDB_OPEN = 1000 }; protected: ComboList * mpList; PegComboBox supports the same style flags and signals as PegList. Demo program PegDemo uses this class. ConstructorThe Rect parameter determines the height of the combo box when open. The closed height is determined by the height of the individual combo box children. Method DrawPegComboBox overrides the draw function to display the combo box border. Method GetOpenHeightReturns the height of the combo box when open. Method IsOpenReturns TRUE if the combo box is currently open, otherwise FALSE. Method MessageCatches the drop down arrow selection message, and the PM_KILLFOCUS system message. Method ResizeKeeps the drop down arrow button positioned at the upper right hand corner of the combo box. Examples:The following are examples of PegComboBox: The following example creates a PegComboBox and adds several PegPrompt objects to the combo box. The combo box will be 140 pixels tall when opened. The combo box is configured to include a vertical scroll bar, and the initial item selected will be item index 5 within the combo box. void MyWindow::AddComboBox(void) { PegRect ListRect; ListRect.Set(10, 10, 90, 150); PEGCHAR cTemp[20]; PegComboBox * pList = new PegComboBox(ListRect); strcpy(cTemp, "Select"); for (iLoop = 10; iLoop > 0; iLoop--) { itoa(iLoop, cTemp + 6, 10); pList->Add(new PegPrompt(0, 0, cTemp, iLoop, FF_NONE | TJ_LEFT | AF_ENABLED | TT_COPY)); } pList->SetScrollMode(WSM_VSCROLL); pList->SetSelected(5); Add(pList); }
|