//=========================================================================== // // File Name: SdTestComboBox.rul // // Description: dialog for testing combo box values // // Comments: required separate SdTestComboBox.rul for custom Test Combobox dialog // // NOTE: any variables you want to persist across screens MUST be passed byref! //=========================================================================== prototype NUMBER ShowDialog_TestComboBox( byref LIST ); // the list // IS Standard Buttons #define BUTTON_NEXT 1 #define BUTTON_BACK 12 // custom controls #define DLG_Name_TestComboBox "SdTestComboBox" #define DLG_cboTest 1201 #define DLG_tboxText 1202 #define DLG_btnAdd 1203 #define DLG_btnDelete 1204 #define DLG_tboxSelectedText 1206 function NUMBER ShowDialog_TestComboBox( lstTest ) STRING szDlg, svSelectedText, svUserText, svTemp; NUMBER nId, listIndex; HWND hwndDlg; BOOL bDone; //debug STRING strDebug; begin szDlg = DLG_Name_TestComboBox; // ensure general initialization is complete if(!bSdInit) then SdInit(); endif; // NOTE: when using completely custom dialogs, the 4th argument of EzDefineDialog must be 0 if( EzDefineDialog( szDlg, ISUSER, szDlg, 0) = DLG_ERR) then return -1; endif; bDone = FALSE; // Loop in dialog until the user selects a standard button while( !bDone ) // Display the dialog and retrieve messages based on the users interaction with the dialog. nId = WaitOnDialog( szDlg ); switch( nId ) // The first message sent before the dialog is displayed. // This is where we can initialize controls in the dialog. case DLG_INIT: hwndDlg = CmdGetHwndDlg( szDlg ); // populate the combo box CtrlSetList( szDlg, DLG_cboTest, lstTest ); // auto-select the first item if ( ListCount( lstTest ) > 0 ) then ListGetFirstString( lstTest, svSelectedText ); CtrlSetCurSel( szDlg, DLG_cboTest, svSelectedText ); CtrlSetText( szDlg, DLG_tboxSelectedText, svSelectedText ); endif; case BUTTON_NEXT: // do nothing for this demo strDebug = "do nothing"; // the user clicked the Cancel or Close button case DLG_CLOSE: SdCloseDlg( hwndDlg, nId, bDone ); case BUTTON_CANCEL: SdCloseDlg( hwndDlg, nId, bDone ); // the user clicked the Back button case BUTTON_BACK: nId = BUTTON_BACK; bDone = TRUE; case DLG_cboTest: // display the selected value if ListCount( lstTest ) > 0 then CtrlGetCurSel( szDlg, DLG_cboTest, svSelectedText ); CtrlSetText( szDlg, DLG_tboxSelectedText, svSelectedText ); else svSelectedText = "LIST IS EMPTY"; endif; case DLG_btnAdd: // add an item to the end of list CtrlGetText( szDlg, DLG_tboxText, svUserText ); listIndex = ListCount( lstTest ); ListSetIndex( lstTest, listIndex - 1 ); ListAddString( lstTest, svUserText, AFTER ); // reset the combobox source with the updated list CtrlSetList( szDlg, DLG_cboTest, lstTest ); // auto-select the newly added item CtrlSetCurSel( szDlg, DLG_cboTest, svUserText ); CtrlSetText( szDlg, DLG_tboxSelectedText, svUserText ); case DLG_btnDelete: // delete an item from the list if ( ListCount( lstTest ) = 0 ) then MessageBox( "The list is empty.", WARNING ); CtrlSetText( szDlg, DLG_tboxSelectedText, "" ); else svSelectedText = ""; CtrlGetCurSel( szDlg, DLG_cboTest, svSelectedText ); ListSetIndex( lstTest, 0 ); // start looking at the beginning of the list ListFindString( lstTest, svSelectedText ); ListDeleteString( lstTest ); // reset the combobox source with the updated list CtrlSetList( szDlg, DLG_cboTest, lstTest ); // auto-select the first item if ( ListCount( lstTest ) > 0 ) then ListGetFirstString( lstTest, svSelectedText ); CtrlSetCurSel( szDlg, DLG_cboTest, svSelectedText ); CtrlSetText( szDlg, DLG_tboxSelectedText, svSelectedText ); endif; endif; default: // check standard handling if(SdIsStdButton( nId ) && SdDoStdButton( nId )) then bDone = TRUE; endif; endswitch; endwhile; // Close the dialog. EndDialog(szDlg); // Release memory used by the dialog. ReleaseDialog(szDlg); // Return the control ID of the control that was clicked. return nId; end;